//
//  LoginViewController.m
//  DemoForWK
//
//  Created by 胡碧涛 on 2018/9/20.
//  Copyright © 2018年 Synjones. All rights reserved.
//

#import "LoginViewController.h"
#import "ViewController.h"


@interface LoginViewController ()
@property(nonatomic, weak)UITextField *userNameTextField;
@property(nonatomic, weak)UITextField *passwordTextField;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
    UILabel *titleLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(30, 130, 100, 35)];
    titleLabel1.text = @"您好,";
    titleLabel1.font = [UIFont boldSystemFontOfSize:28];
    [self.view addSubview:titleLabel1];
    UILabel *titleLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(30, titleLabel1.bottom, 300, 35)];
    titleLabel2.text = @"欢迎来到智慧校园";
    titleLabel2.font = [UIFont boldSystemFontOfSize:28];
    [self.view addSubview:titleLabel2];
    
    UIImageView *usernameImageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, titleLabel2.bottom+35, 30, 30)];
    usernameImageView.image = [UIImage imageNamed:@"phone"];
    [self.view addSubview:usernameImageView];
    UITextField *userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(usernameImageView.right, usernameImageView.y-10, kScreenWidth-100, 50)];
    self.userNameTextField = userNameTextField;
    userNameTextField.placeholder = @"输入登录账号";
    [self.view addSubview:userNameTextField];
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(userNameTextField.x, userNameTextField.bottom, userNameTextField.width, 1)];
    lineView1.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:lineView1];
    
    UIImageView *passwordImageView = [[UIImageView alloc] initWithFrame:CGRectMake(usernameImageView.x, lineView1.bottom+20, 30, 30)];
    passwordImageView.image = [UIImage imageNamed:@"mima"];
    [self.view addSubview:passwordImageView];
    UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(passwordImageView.right, passwordImageView.y-10, kScreenWidth-100, 50)];
    self.passwordTextField = passwordTextField;
    passwordTextField.placeholder = @"请输入门户/校园卡密码";
    [self.view addSubview:passwordTextField];
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(passwordTextField.x, passwordTextField.bottom, passwordTextField.width, 1)];
    lineView2.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:lineView2];

    UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(30, lineView2.bottom+40, kScreenWidth-60, 50)];
    loginButton.layer.cornerRadius = 25;
    loginButton.backgroundColor = [UIColor colorWithHexString:@"999999"];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];
}


- (void)loginAction{
    ViewController *VC = [[ViewController alloc] init];
    if ([self.userNameTextField.text isEqualToString: @"1"] && [self.passwordTextField.text isEqualToString: @"111"]) {
        int randomNum = 10000000 +  (arc4random() % 10000001);
        NSString *token = [NSString stringWithFormat:@"%d", randomNum];
        VC.token = token;
        [self.navigationController pushViewController:VC animated:YES];
    } else {
        [self.view makeToast:@"用户名密码错误"];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
